import './src/assets/style/common.less'
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

const scene = new THREE.Scene()

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)

const renderer = new THREE.WebGLRenderer({
    antialias:true,  // 开启锯齿
})

renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild( renderer.domElement );

const geometry = new THREE.BoxGeometry()
// 创建漫反射材质
// const material = new THREE.MeshLambertMaterial({ 
//     color: 0x66ccff, 
//     side: THREE.DoubleSide  // 内部可见/两面可见
// })
// 创建高光反射材质
const material = new THREE.MeshPhongMaterial({
  color: 0x66ccff,
  shininess: 500, //高光部分的亮度，默认30
  specular: 0x444444, //高光部分的颜色
})
// 创建点光源
const pointLight = new THREE.PointLight(0xffffff, 1.0);
// 设置点光源位置
pointLight.position.set(15, 15, 15);
// 设置光照强度
pointLight.intensity = 50.0
// 设置光源随距离衰减的值
pointLight.decay = 1.0;
// 将点光源添加到场景中
scene.add(pointLight)
// 创建环境光
const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
// 将环境光添加到场景中
scene.add(ambientLight)
const cube = new THREE.Mesh(geometry, material)

scene.add(cube)

camera.position.z = 5
// 控制器--轨道控制器
// const controls = new OrbitControls(camera, renderer.domElement)
// controls.autoRotate = true
// 添加坐标轴辅助器
// const axesHelper = new THREE.AxesHelper(5)
// scene.add(axesHelper)

function animate() {
  // cube.rotation.x += 0.005
  // cube.rotation.z += 0.005
  // controls.update()
  renderer.render( scene, camera );
  requestAnimationFrame(animate)
}

animate()



function fn() {
  const numPoints = 50, goldenRatio = 1.618, radius = 100
  const smallBallGeometry = new THREE.SphereGeometry(5)

  for (let i = 0; i < numPoints; i++) {
    const y = 1 - (i / (numPoints - 1)) * 2
    const radiusAtY = Math.sqrt(1 - y * y)

    const theta = (2 * Math.PI * i) / goldenRatio

    const x = Math.cos(theta) * radiusAtY
    const z = Math.sin(theta) * radiusAtY
    const smallBallMaterial = new THREE.MeshBasicMaterial({
      color: '#fff',
      depthWrite: true,
      depthTest: true,
      side: THREE.FrontSide,
    })
    const smallBall = new THREE.Mesh(smallBallGeometry, smallBallMaterial)
    scene.add(smallBall)
    smallBall.position.set(x * radius, y * radius, z * radius)
  }
}